package name.ljd.ch9_1.security;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.core.userdetails.UserDetails;
import org.springframework.security.core.userdetails.UserDetailsService;
import org.springframework.security.core.userdetails.UsernameNotFoundException;

import name.ljd.ch9_1.dao.SysUserRepository;
import name.ljd.ch9_1.domain.SysUser;

public class CustomUserService implements UserDetailsService {
	@Autowired
	SysUserRepository sysUserRepository;
	@Override
	public UserDetails loadUserByUsername(String username) throws UsernameNotFoundException {
		SysUser user = sysUserRepository.findByUsername(username);
		if(user == null) {
			throw new UsernameNotFoundException("用户不存在");
		}
		return user;
	}

}
